//
//  ZYCProfileFaceEntryView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/13.
//

#import "ZYCProfileFaceEntryView.h"
#import "ZYCCustomTipView.h"
@interface ZYCProfileFaceEntryView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIButton *cameraButton;
@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) UIButton *cancelButton;


@end
@implementation ZYCProfileFaceEntryView

- (void)setType:(ZYCProfileFaceEntryViewType)type{
    _type = type;
    if (type == ZYCProfileFaceEntryViewTypePhoto) {
        _titleLabel.hidden = YES;
        _contentLabel.hidden = YES;
        CGFloat margin = (kScreenWidth - 83 * 3) / 4;
        for (NSInteger i = 0; i < self.titleArr.count; i++) {
            ZYCCustomTipView *vc = [[ZYCCustomTipView alloc] init];
            vc.dict = self.titleArr[i];
            [self addSubview:vc];
            [vc mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(83.0, 120));
                make.left.equalTo(self).offset((i+1) * margin + i * 83.0f);
                make.top.equalTo(self.kuangImageView.mas_bottom).offset(68.0f);
            }];
        }
    }else{
        _titleLabel.hidden = NO;
        _contentLabel.hidden = NO;
    }
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.kuangImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.contentLabel];
        [self addSubview:self.cameraButton];

        [self.kuangImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(270.0f, 270.0f));
            make.top.equalTo(self).offset(36.0f);
            make.centerX.equalTo(self);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.kuangImageView.mas_bottom).offset(68.0f);
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(10.0f);
            make.width.mas_equalTo(230.0f);
        }];
        
        [self.cameraButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(63.0f);
            make.right.equalTo(self).offset(-63.0f);
            make.top.equalTo(self.contentLabel.mas_bottom).offset(47.0f);
            make.height.mas_equalTo(40.0f);
        }];
    }
    return self;
}

- (UIImageView *)kuangImageView {
    if (!_kuangImageView) {
        _kuangImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"kuang"]];
        _kuangImageView.userInteractionEnabled = YES;
    }
    return _kuangImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithString:@"照片要求" Font:kCustomFont(@"PingFangSC-Regular", 18.0f) titleColor:HEX_RGB(@"#2B302D") textAlignment:ZZTextAlignmentCenter];
    }
    return _titleLabel;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 18.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentCenter];
        _contentLabel.text = @"彩色人脸大头照(肩部以上)\n不可拉伸,压缩图片\n露出耳朵,面部无遮挡";
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (NSArray *)titleArr {
    if (!_titleArr) {
        _titleArr = @[@{@"title":@"光线充足正对手机",@"imageName":@"a"},
                      @{@"title":@"不要在黄昏或逆光下扫描",@"imageName":@"b"},
                      @{@"title":@"放慢动作不要斜视手机",@"imageName":@"c"}];
    }
    return _titleArr;
}


- (UIButton *)cameraButton {
    if (!_cameraButton) {
        _cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _cameraButton.frame = CGRectMake(0,0, kScreenWidth - 2 * 63, 40);
        [_cameraButton setTitle:@"确认上传" forState:UIControlStateNormal];
        [_cameraButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        _cameraButton.backgroundColor = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0];
        _cameraButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 18.0f);
        [_cameraButton addTarget:self action:@selector(clickCameraAction:) forControlEvents:UIControlEventTouchUpInside];
        _cameraButton.layer.cornerRadius = 15;
        _cameraButton.layer.masksToBounds = YES;
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.colors = @[(__bridge id)HEX_RGB(@"#F6EEB0").CGColor,
                                 (__bridge id)HEX_RGB(@"#009B4C").CGColor];
        gradientLayer.locations = @[@(0.3),@(1.0f)];
        gradientLayer.frame = _cameraButton.bounds;
        gradientLayer.cornerRadius = 15;
        [_cameraButton.layer insertSublayer:gradientLayer atIndex:0];
    }
    return _cameraButton;
}



- (void)clickCameraAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(profileFaceEntryViewClickComfirm)]) {
        [self.delegate profileFaceEntryViewClickComfirm];
    }
}


@end
